<template>
  <div class="loginBj">
    <div class="login">
      <div class="logoImg">
        <img src="../../static/img/logo.png" style="width: 300px; margin: 0 0 30px 50px;" alt="">
      </div>
      <el-form :model="loginForm" ref="loginForm" :rules="rules">
        <el-form-item prop="username">
          <el-input type="text" placeholder="请输入用户名" v-model.trim="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" placeholder="请输入密码" v-model="loginForm.password" @keyup.enter.native="submitForm('loginForm')"></el-input>
        </el-form-item>
        <el-form-item>
          <div class="loginBtn" @click="submitForm('loginForm')">
            登&nbsp;&nbsp;录
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {mapMutations} from 'vuex'
let vm;
export default {
  data () {
    return {
      loginForm: {
        username: 'admin',
        password: 'admin',
      },
      rules: {
        username: [
          {required: true, message: '请输入登录名', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ]
      },
    }
  },
  created() {
    vm = this;
  },
  beforeDestroy() {
      console.log('logindestroy')
    },
  methods: {
    ...mapMutations(['setUserInfo','setRelocalMenu']),
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if(valid){
          let token = '123456'
          sessionStorage.setItem('token', token);
          if(vm.loginForm.username == 'admin' && vm.loginForm.password == 'admin'){
            this.$store.dispatch('dealPermission', token).then(res => {
              this.$router.push({path:'/index'});
            })
          }else{
            vm.alert.error("账号密码错误")
          }
        }else{
          return false;
        }
      });
    }
  }
}
</script>
<style scoped>
.loginBj{
  width: 100%;
  height: 100%;
  background: url(../../static/img/login-bg.png) no-repeat;
  background-size: 100% 100%;
  display: inline-block;
}
.loginBj .login{
  position: fixed;
  width: 400px;
  height: 300px;
  background-color: #fff;
  padding: 50px 75px;
  border-radius: 10px;
  top: 50%;
  left: 50%;
  margin-top: -200px;
  margin-left: -255px;
}
.loginBj .login .loginBtn{
  width: 100%;
  height: 44px;
  line-height: 44px;
  font-size: 16px;
  color: #ffffff;
  margin-top: 20px;
  text-align:center;
  background-color: #f73b42 !important;
  border: 1px solid #f73b42 !important;
}
.loginBj .login .loginBtn:hover{
  background-color: #f82931 !important;
  border: 1px solid #f82931 !important;
}
</style>